import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPersist from "vuex-persist";
export default new Vuex.Store({
  state: {
    list: [],
  },
  mutations: {
    setlist(state, list) {
      state.list = list;
    },
    adds(state, index) {
      state.list[index].count++;
    },
    min(state, index) {
      state.list[index].count--;
    },
    del(state, index) {
      state.list[index].count = 0;
    },
    clear(state) {
      state.list.forEach((item) => {
        item.count = 0;
      });
    },
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      localstorage: window.localStorage,
    }).plugin,
  ],
});
